package cn.seocoo.platform.api.controller;

import cn.seocoo.platform.api.util.JSONResult;
import cn.seocoo.platform.base.dto.BaseCommonDto;
import cn.seocoo.platform.common.constant.ClassContants;
import cn.seocoo.platform.common.core.domain.AjaxResult;
import cn.seocoo.platform.common.utils.StringUtils;
import cn.seocoo.platform.report.domain.Report;
import cn.seocoo.platform.report.service.IReportService;
import cn.seocoo.platform.system.domain.SysDictData;
import cn.seocoo.platform.system.service.ISysDictDataService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: ApiReportController
 * @description: 举报操作
 * @author: wujian
 * @Date: 2019-12-23 10:56
 **/
@Api(value = "举报")
@RestController
@RequestMapping("/api/report")
public class ApiReportController {

    @Autowired
    private ISysDictDataService iSysDictDataService;

    @Autowired
    private IReportService iReportService;

    /**
     * @return
     * @Author WuJian
     * @Description //获取举报类型
     * @Date 11:07 2019/12/23
     * @Param
     **/

    @GetMapping("/getReportTypeList")
    public AjaxResult getReportTypeList() {
        List<SysDictData> sys = iSysDictDataService.selectDictDataByType(ClassContants.REPORT_TYPE_DICT);
        List<BaseCommonDto> list = new ArrayList<>();
        for (SysDictData sy : sys) {
            BaseCommonDto dto = new BaseCommonDto();
            dto.setId(sy.getDictValue());
            dto.setText(sy.getDictLabel());
            list.add(dto);
        }
        return AjaxResult.success(list);
    }


    /**
     * @return
     * @Author WuJian
     * @Description //举报
     * @Date 11:07 2019/12/23
     * @Param
     **/
    @PostMapping("/saveReport")
    public AjaxResult saveReport(@RequestBody Report report) {
        try {
            if (StringUtils.isBlank(report.getBaseReportType())) {
                return AjaxResult.error("请选择举报类型");
            }
            if (report.getReportVihicleId() == null ) {
                return AjaxResult.error("请选择举报车辆");
            }
            if (report.getAppUserId() == null) {
                return AjaxResult.error("请重新登录账号");
            }
            int row = iReportService.saveReport(report);
            if(row > 0){
                return AjaxResult.success("举报成功");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return AjaxResult.error(AjaxResult.ERROR_MSG);
    }

}
